package com.ksd.modules.system.controller;

import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.modules.system.entity.AdminSystem;
import com.ksd.modules.system.po.AdminSystemUserSavePO;
import com.ksd.modules.system.service.IAdminSystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 系统 前端控制器
 * </p>
 *
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
public class AdminSystemUserController extends BaseController {

    @Autowired
    private IAdminSystemUserService adminSystemUserService;


    /**
     * 查询用户绑定的系统
     * @param userId
     * @return
     */
    @PostMapping("/system/user/list/{userId}")
    public R<List<AdminSystem>> findAdminSystem(@PathVariable("userId")Long userId) {
        return R.data(adminSystemUserService.findAdminSystemAll(userId));
    }

    /**
     * 绑定用户和系统关系
     *
     * @param adminSystemUserSavePO
     * @return
     */
    @PostMapping("/system/user/bind")
    @ApiLog("系统保存和更新")
    public R<Boolean> bindSystemByUserId(@Validated @RequestBody AdminSystemUserSavePO adminSystemUserSavePO) {
        return R.data(adminSystemUserService.bindSystemByUserId(adminSystemUserSavePO.getUserId(),adminSystemUserSavePO.getSystemId()));
    }

    /**
     * 解绑绑定用户和系统关系
     *
     * @param adminSystemUserSavePO
     * @return
     */
    @PostMapping("/system/user/unbind")
    public R<Boolean> unbindSystemByUserId(@Validated @RequestBody AdminSystemUserSavePO adminSystemUserSavePO) {
        return R.data(adminSystemUserService.unbindSystemByUserId(adminSystemUserSavePO.getUserId(),adminSystemUserSavePO.getSystemId()));
    }
}
